﻿using System;
using System.Collections.Generic;
using System.Linq;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.Hr;


namespace HengTong.ViewModel.Person.SysPersonWorkVms
{
    public partial class SysPersonWorkListVm : BasePagedListVM<SysPersonWorkView, SysPersonWorkSearcher>
    {

        protected override IEnumerable<IGridColumn<SysPersonWorkView>> InitGridHeader()
        {
            return new List<GridColumn<SysPersonWorkView>>{
                this.MakeGridHeader(x => x.PersonName),
                this.MakeGridHeader(x => x.Company),
                this.MakeGridHeader(x => x.Position),
                this.MakeGridHeader(x => x.StartDate),
                this.MakeGridHeader(x => x.EndDate),
                this.MakeGridHeader(x => x.Reference),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysPersonWorkView> GetSearchQuery()
        {
            var query = DC.Set<SysPersonWork>()
                .CheckEqual(Searcher.PersonId, x=>x.PersonId)
                .CheckContain(Searcher.Company, x=>x.Company)
                .Select(x => new SysPersonWorkView
                {
				    ID = x.ID,
                    PersonName = x.Person.Name,
                    Company = x.Company,
                    Position = x.Position,
                    StartDate = x.StartDate,
                    EndDate = x.EndDate,
                    Reference = x.Reference,
                })
                .OrderBy(x => x.StartDate ?? DateTime.MaxValue);
            return query;
        }

    }

    public class SysPersonWorkView : SysPersonWork{
        [Display(Name = "姓名")]
        public String PersonName { get; set; }

    }
}
